/*  */
var fontSize=15;
var fontSize2=16;
var splitNumber=12;
var chartW=$(window).width();
if(chartW>1500){
    $('.chart').css('width',chartW);
}else{
    $('.chart').css('width',chartW*3);
}

if (u.indexOf('iPhone') > -1) {   //苹果手机
    fontSize=fontSize*2;
    fontSize2=fontSize2*2;
}
$(function () {
    //appToken='79b9245256a9c20b582f84c16ec8518a';
    //appUserId='1596';

    var myChart = echarts.init(document.getElementById('chart'));

    //初始化图表
   // queryPersonalOccupationTime()

    if (u.indexOf('iPhone') > -1) {   //苹果手机
        setTimeout(function () {
            WebViewJavascriptBridge.callHandler('getPartCode', {'foo': 'bar'}, function(response) {
                /*layer.open({
                    content: response
                    ,btn: '确定'
                });*/
                response=JSON.parse(response);
                appToken=response.token;
                appUserId=response.userId;
                localStorage.appToken=appToken;
                localStorage.appUserId=appUserId;
                //初始化图表
                queryPersonalOccupationTime()
            })
        },50);
    }else {
        var response=jsObj.getPartCode();
        response=JSON.parse(response);
        appToken=response.token;
        appUserId=response.userId;
        localStorage.appToken=appToken;
        localStorage.appUserId=appUserId;
        //初始化图表
        queryPersonalOccupationTime()
    }


    /* 条件选择*/
    function strLen(str) {
        if(str.length>4){
            return str.substr(0,4)+'...';
        }else{
            return str;
        }
    };
    //显示条件选择框
    var topNavLiEve='';
    $('.topNav li').click(function () {
        $('.topNav li').removeClass('active');
        topNavLiEve=$(this).attr('data-type');
        $(this).addClass('active');
    });
    //点击条件选择框最终条件
    $('.topNavSelect.type .list.active li').click(function () {
        $('.topNav li').removeClass('active');
        $('.topNavSelect').hide();
        $(topNavLiEve).children('span').html();
    });

    $('.topNavSelect .bj').click(function () {
        $('.topNav li').removeClass('active');
        $('.topNavSelect').hide();
    })

    /* 类型选择效果 */
    $('body').on('click', '.topNavTypeUl li', function () {
        $(this).parent('.topNavTypeUl').children('li').removeClass('active');
        $(this).addClass('active');
        $(this).parent('.topNavTypeUl').animate({scrollLeft: $(this).get(0).offsetLeft - ($(this).parent('.topNavTypeUl').width() / 2) + ($(this).children('div').get(0).clientWidth / 2)}, 300);
    });
    $('.topNavTypeUl').each(function () {
        $(this).animate({scrollLeft: $(this).find('.active').get(0).offsetLeft - ($(this).width() / 2) + ($(this).find('.active').children('div').get(0).clientWidth / 2)}, 1);
    })


    /* 扇形图表 */
    var option1 = {
        title : {
            text: '',
            subtext: '',
            x:'center'
        },
        tooltip : {
            trigger: 'item',
            textStyle:{
                fontSize:fontSize,
            },
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            textStyle:{
                fontSize:fontSize,
            },
            pageTextStyle:{
                fontSize:fontSize2,
            },
            pageIconSize:fontSize2,
            bottom: 0,
            data: ['杭州巨量科技股份有限公司','TCL集团股份有限公司','长安福特汽车有限公司','锤子科技(北京)有限公司','珠海格力集团有限公司','创维集团有限公司','杭州巨量科技股份有限公司1','TCL集团股份有限公司1','长安福特汽车有限公司1','锤子科技(北京)有限公司1','珠海格力集团有限公司1','创维集团有限公司1']
        },
        series : [
            {
                name:'',
                type:'pie',
                radius : '45%',
                center: ['50%', '50%'],
                label: {
                    normal: {
                        show: true,
                        fontSize:fontSize,
                        formatter: "{b}({d}%)"
                    }
                },
                data:[
                    {value:335, name:'杭州巨量科技股份有限公司'},
                    {value:410, name:'TCL集团股份有限公司'},
                    {value:514, name:'长安福特汽车有限公司'},
                    {value:355, name:'锤子科技(北京)有限公司'},
                    {value:370, name:'珠海格力集团有限公司'},
                    {value:390, name:'创维集团有限公司'},
                    {value:555, name:'杭州巨量科技股份有限公司1'},
                    {value:600, name:'TCL集团股份有限公司1'},
                    {value:654, name:'长安福特汽车有限公司1'},
                    {value:705, name:'锤子科技(北京)有限公司1'},
                    {value:750, name:'珠海格力集团有限公司1'},
                    {value:800, name:'创维集团有限公司1'}
                ].sort(function (a, b) { return a.value - b.value; }),
                roseType: 'radius',

            }
        ]
    };
    /* 拆线图表 */
    var option2 = {
        title: {
            text: ''
        },
        tooltip : {
            trigger: 'item',
            textStyle:{
                fontSize:fontSize,
            },
            formatter: "{b}<br/>{a} {c}%"
        },
        legend: {
            textStyle:{
                fontSize:fontSize,
            },
            pageTextStyle:{
                fontSize:fontSize2,
            },
            pageIconSize:fontSize2,
            bottom: 0,
            data:['设备有效稼动率','生产效率','良品率','综合设备效率']
        },
        grid: {
            left: '3%',
            right: '5%',
            bottom: '10%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                boundaryGap : false,
                splitNumber:splitNumber,
                axisLabel:{
                    fontSize:fontSize,
                },
                data : ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月']
            }
        ],
        yAxis : [
            {
                type : 'value',
                axisLabel: {
                    fontSize:fontSize,
                    formatter: '{value}%'   //设置Y轴的单位
                },
                max: function(value) {
                    if(value.max<100){
                        return 100;
                    }else{
                        return value.max
                    }
                }
            }
        ],

        series : [
            {
                name:'设备有效稼动率',
                type:'line',
                symbolSize:fontSize,
                smooth: true,
                data:[null,null,null,80,95, 79, 63, 40, 77, 85, null,null,null,]
            },
            {
                name:'生产效率',
                type:'line',
                symbolSize:fontSize,
                smooth: true,
                data:[null,null,null,70,83, 63, 58, 65, 75, 80, null,null,null,]
            },
            {
                name:'良品率',
                type:'line',
                symbolSize:fontSize,
                smooth: true,
                data:[null, null,null,60,75, 58, 42, 55, 65, null,null,null,null,]
            },
            {
                name:'综合设备效率',
                type:'line',
                symbolSize:fontSize,
                smooth: true,
                data:[null, null,null,25,50, 30, 10, 25, 42,null,null,null,null,]
            }
        ]
    };

    /* 拆线树状图表 */
    var colors = ['#5793f3', '#d14a61', '#675bba'];
    var option3 = {
        color: colors,
        tooltip : {
            trigger: 'item',
            textStyle:{
                fontSize:fontSize,
            },
            formatter: "{a} <br/>{b} : {c}"
        },
        legend: {
            textStyle:{
                fontSize:fontSize,
            },
            pageTextStyle:{
                fontSize:fontSize2,
            },
            pageIconSize:fontSize2,
            bottom: 0,
            data:['平均有效稼动时间','平均理论稼动时间','设备有效稼动']
        },
        grid: {
            bottom: '15%',
        },
        xAxis: [
            {
                type: 'category',
                splitNumber:splitNumber,
                axisLabel:{
                    fontSize:fontSize,
                },
                axisTick: {
                    alignWithLabel: true
                },
                data: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月']
            }
        ],
        yAxis: [
            {
                type: 'value',
                name: '时间（h）',
                min: 0,
                max: function(value) {
                    return value.max + (parseInt(value.max/3));
                },
                position: 'right',
                axisLine: {
                    lineStyle: {
                        color: colors[0]
                    }
                },
                nameTextStyle: {
                    fontSize:fontSize,
                },
                axisLabel: {
                    fontSize:fontSize,
                    formatter: '{value}'
                }
            },
            {
                type: 'value',
                name: '设备有效稼动',
                min: 0,
                top:1,
                max: function(value) {
                    if(value.max<100){
                        return 100;
                    }else{
                        return value.max
                    }
                },
                position: 'left',
                axisLine: {
                    lineStyle: {
                        color: colors[2]
                    }
                },
                nameTextStyle: {
                    fontSize:fontSize,
                },
                axisLabel: {
                    fontSize:fontSize,
                    formatter: '{value} %'
                }
            }
        ],
        series: [
            {
                name:'平均有效稼动时间',
                type:'bar',
                label: {
                    normal: {
                        show: true,
                        fontSize:fontSize,
                        position: 'top',
                        formatter: "{c}"
                    }
                },
                data:[2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
            },
            {
                name:'平均理论稼动时间',
                type:'bar',
                label: {
                    normal: {
                        show: true,
                        fontSize:fontSize,
                        position: 'top',
                        formatter: "{c}"
                    }
                },
                data:[2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
            },
            {
                name:'设备有效稼动',
                type:'line',
                yAxisIndex: 1,
                symbolSize:fontSize,
                smooth: true,
                label: {
                    normal: {
                        show: true,
                        fontSize:fontSize,
                        formatter: "{c}%"
                    }
                },
                data:[95, 90, 80, 78, 82, 93, 80, 85, 95, 90, 85, 90]
            }
        ]
    };

    /* 进度图表 */
    var itemStyle1= {
        normal: {
            opacity: 0.8,
            color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 1,
                y2: 0,
                colorStops: [{
                    offset: 0, color: '#fde663' // 0% 处的颜色
                }, {
                    offset: 1, color: '#fdd063' // 100% 处的颜色
                }],
                globalCoord: false // 缺省为 false
            }
        }
    }
    var itemStyle2= {
        normal: {
            opacity: 0.8,
            color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 1,
                y2: 0,
                colorStops: [{
                    offset: 0, color: '#41d9bb' // 0% 处的颜色
                }, {
                    offset: 1, color: '#27c3d1' // 100% 处的颜色
                }],
                globalCoord: false, // 缺省为 false
            }
        },

    }
    var itemStyle3= {
        normal: {
            opacity: 0.15,
            color: {
                type: 'linear',
                x: 0,
                y: 0,
                x2: 1,
                y2: 0,
                colorStops: [{
                    offset: 0, color: '#41d9bb' // 0% 处的颜色
                }, {
                    offset: 1, color: '#27c3d1' // 100% 处的颜色
                }],
                globalCoord: false, // 缺省为 false
            }
        },
    }

    var Ydata=['SPP143(小拉杆）', 'LPP143(大拉杆）', 'LP624(导柱）', 'BCP215(下固定板）', 'TCP215(上固定板）'];
    var Xtype='月';
    var splitNumberLen=13;
    var data = [
        {
            "value":[0,2,3.5,'计划开始时间：2017/02/01 14:00','计划结束时间：2017/03/15 14:00'],
        },
        {
            "value":[1,3,4,'计划开始时间：2017/03/01 14:00','计划结束时间：2017/04/30 14:00'],
        },
        {
            "value":[2,5,6,'计划开始时间：2017/05/01 14:00','计划结束时间：2017/06/30 14:00'],
        },
        {
            "value":[3,5,6,'计划开始时间：2017/05/01 14:00','计划结束时间：2017/06/30 14:00'],
        },
        {
            "value":[4,5,6,'计划开始时间：2017/05/01 14:00','计划结束时间：2017/06/30 14:00'],
        }
    ];
    var data2 = [
        {
            "value":[0,7,8,'实际开始时间：2017/07/01 14:00','预计结束时间：2017/08/30 14:00'],
        },
        {
            "value":[1,9,10,'实际开始时间：2017/09/01 14:00','预计结束时间：2017/10/19 14:00'],
        },
        {
            "value":[2,10,11,'实际开始时间：2017/10/01 14:00','预计结束时间：2017/11/30 14:00'],
        },
        {
            "value":[3,10,11,'实际开始时间：2017/10/01 14:00','预计结束时间：2017/11/30 14:00'],
        },
        {
            "value":[4,10,11,'实际开始时间：2017/10/01 14:00','预计结束时间：2017/11/30 14:00'],
        }
    ];
    var data3 = [
        {
            "value":[0,7,9,'实际开始时间：2017/07/01 14:00','预计结束时间：2017/09/30 14:00'],
        },
        {
            "value":[1,9,10.5,'实际开始时间：2017/09/01 14:00','预计结束时间：2017/10/02 14:00'],
        },
        {
            "value":[2,10,12,'实际开始时间：2017/10/01 14:00','预计结束时间：2017/12/28 14:00'],
        },
        {
            "value":[3,10,12,'实际开始时间：2017/10/01 14:00','预计结束时间：2017/12/30 14:00'],
        },
        {
            "value":[4,10,12,'实际开始时间：2017/10/02 14:00','预计结束时间：2017/12/30 14:00'],
        }
    ];


    for(var i=0;i<data.length;i++){
        data[i].itemStyle=itemStyle1;
    }
    for(var i=0;i<data2.length;i++){
        data2[i].itemStyle=itemStyle2;
    }
    for(var i=0;i<data3.length;i++){
        data3[i].itemStyle=itemStyle3;
    }

    function renderItem(params, api) {
        var categoryIndex = api.value(0);
        var start = api.coord([api.value(1), categoryIndex]);
        var end = api.coord([api.value(2), categoryIndex]);
        var height = api.size([0, 1])[1] * 0.2;

        return {
            type: 'rect',
            shape: echarts.graphic.clipRectByRect({
                x: start[0],
                y: start[1] - height/1,
                width: end[0] - start[0],
                height: height
            }, {
                x: params.coordSys.x,
                y: params.coordSys.y,
                width: params.coordSys.width,
                height: params.coordSys.height
            }),
            style: api.style()
        };
    }
    function renderItem2(params, api) {
        var categoryIndex = api.value(0);
        var start = api.coord([api.value(1), categoryIndex]);
        var end = api.coord([api.value(2), categoryIndex]);
        var height = api.size([0, 1])[1] * 0.2;

        return {
            type: 'rect',
            shape: echarts.graphic.clipRectByRect({
                x: start[0],
                y: start[1],
                width: end[0] - start[0],
                height: height
            }, {
                x: params.coordSys.x,
                y: params.coordSys.y,
                width: params.coordSys.width,
                height: params.coordSys.height
            }),
            style: api.style()
        };
    }
    function renderItem3(params, api) {
        var categoryIndex = api.value(0);
        var start = api.coord([api.value(1), categoryIndex]);
        var end = api.coord([api.value(2), categoryIndex]);
        var height = api.size([0, 1])[1] * 0.2;

        return {
            type: 'rect',
            shape: echarts.graphic.clipRectByRect({
                x: start[0],
                y: start[1],
                width: end[0] - start[0],
                height: height
            }, {
                x: params.coordSys.x,
                y: params.coordSys.y,
                width: params.coordSys.width,
                height: params.coordSys.height
            }),
            style: api.style()
        };
    }


    var option4 = {
        tooltip: {
            textStyle:{
                fontSize:fontSize,
            },
            formatter: function (params) {
                return params.value[3] + '<br/>' +params.value[4];
            }
        },
        legend: {
            textStyle:{
                fontSize:fontSize,
            },
            pageTextStyle:{
                fontSize:fontSize2,
            },
            pageIconSize:fontSize2,
            bottom:0,
            data: ['计划进度', '实际已完成进度', '实际未完成进度']
        },
        grid: {
            left: '3%',
            right: '5%',
            bottom: '15%',
            containLabel: true
        },
        xAxis: {
            scale: true,
            min:0,
            max:splitNumberLen,
            nameTextStyle: {
                fontSize:fontSize,
            },
            axisLabel: {
                fontSize:fontSize,
                formatter: function (val) {
                    if(val==0||val==splitNumberLen){
                        return '';
                    }else{
                        return Math.max(val) + Xtype;
                    }

                }
            },
            splitNumber:splitNumberLen
        },
        yAxis: {
            nameTextStyle: {
                fontSize:fontSize,
            },
            axisLabel: {
                fontSize:fontSize,
            },
            name:'生产单名称',
            data: Ydata,
        },
        series: [{
            type: 'custom',
            name:'计划进度',
            renderItem: renderItem,
            itemStyle: itemStyle1,
            encode: {
                x: [1, 2],
                y: 0
            },
            data: data
        },{
            type: 'custom',
            name:'实际已完成进度',
            renderItem: renderItem2,
            itemStyle: itemStyle2,
            encode: {
                x: [1, 2],
                y: 0
            },
            z:2,
            data: data2
        },{
            type: 'custom',
            name:'实际未完成进度',
            renderItem: renderItem3,
            itemStyle: {
                normal: {
                    opacity: 0.15,
                    color: {
                        type: 'linear',
                        x: 0,
                        y: 0,
                        x2: 1,
                        y2: 0,
                        colorStops: [{
                            offset: 0, color: '#d6edee' // 0% 处的颜色
                        }, {
                            offset: 1, color: '#d6edee' // 100% 处的颜色
                        }],
                        globalCoord: false, // 缺省为 false
                    }

                },
            },
            encode: {
                x: [1, 2],
                y: 0
            },
            z:1,
            data: data3
        }]
    };

    /*
    * myChart.showLoading();
    * myChart.hideLoading();
    * */
    /* 请求方法 */
    //获取部门与设备类型
    function findOrgAndEquipmentType() {
        var url='/mes/statis/findOrgAndEquipmentType';
        var mdObj=md5Fun(appUserId,url,appToken);
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                //alert(data)
                //layer.closeAll();
                console.log(data);
                if(data.code==100){
                    $('.spinner').hide();
                    $('.main').show();
                    content=Decrypt(data.content);
                    historyObjStr=content;
                    content=JSON.parse(content);
                    console.log(content)
                    var historyHtml='';
                    if(content.list.length>0){
                        for(var i=0;i<content.list.length;i++){
                            historyHtml+='<li data-len='+i+'>' +
                                '<div class="title">零件监控编号：'+content.list[i].partCode+'<span>2017-12-06 08:00</span></div>' +
                                '<div class="content">' +
                                '<p><span>零件名称：</span>'+content.list[i].partName+'</p>' +
                                '<p><span>生产单号：</span>'+content.list[i].productionCode+'</p>' +
                                '<p><span>产品名称：</span>'+content.list[i].productName+'</p>' +
                                '<p><span>质检名称：</span>'+content.list[i].qualityName+'</p>' +
                                '<p><span>质检时间：</span>'+content.list[i].hours+'</p>' +
                                '</div>' +
                                '<div class="content">' +
                                '<div class="bottomBut"><span class="info">查看详情<i class="icon iconfont icon-jiantou2"></i></span></div>' +
                                '</div>' +
                                '</li>';
                        }
                    }else{
                        historyHtml='<div style="text-align: center; color: #888888; padding-top: 1rem; font-size: 0.35rem;">暂无数据</div>';
                    }
                    if(indexPage==1){
                        $('.TabMainUl').html(historyHtml);
                    }else{
                        $('.TabMainUl').append(historyHtml);
                    }
                    pageNum=data.content.pageNum;
                    if(data.content.pageNum>10){
                        pullUpEl = document.getElementById('pullUp');
                        pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多';
                        pullUpEl.className = '';
                        document.getElementById('pullUp').style.display='block';
                    }else{
                        document.getElementById('pullUp').style.display='none';
                    }
                    myScroll.refresh();
                }else{
                    $('.spinner').hide();
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                //layer.closeAll();
                $('.spinner').hide();
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });
    }
    //物料统计 1 1 3
    function queryMaterialDate(urlType) {
        var url='/mes/statis/queryMaterialDate';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {
            "type":'',
            "month":'',
            "yeas":'',
            "customerName":''
        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        console.log(Decrypt(parameter));
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            data:JSON.stringify(
                {"parameter":parameter}
            ),
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                console.log(data)
                if(data.code==100){
                    var content=Decrypt(data.content);
                    content=JSON.parse(content);
                    console.log(content)
                    if(urlType=='A'){//领取物料总重
                        option1.legend.data=content.customerNameList;
                        option1.series[0].data=content.metailDtos;
                        myChart.hideLoading();
                        if(dataType!='1'){$('.chartBox').animate({scrollLeft: 0}, 1);}
                        myChart.setOption(option1,true);
                        if(content.metailDtos.length==0){
                            layer.open({
                                content: '暂无数据'
                                ,btn: '确定'
                            });
                        }
                    }else if(urlType=='B'){//耗损物料总重
                        option1.legend.data=content.customerNameList;
                        option1.series[0].data=content.spoilageTotalMaps;
                        myChart.hideLoading();
                        if(dataType!='1'){$('.chartBox').animate({scrollLeft: 0}, 1);}
                        myChart.setOption(option1,true);
                        if(content.spoilageTotalMaps.length==0){
                            layer.open({
                                content: '暂无数据'
                                ,btn: '确定'
                            });
                        }
                    }else if(urlType=='C'){
                        option3.legend.data=['领取物料总重','耗损物料总重','物料损耗率'];
                        option3.xAxis[0].data=content.customerNameList;
                        option3.yAxis[0].name='重量（Kg）';
                        option3.yAxis[1].name='物料总损耗率';

                        var metailDtosArr=[];//领取物料总重
                        for(var i=0;i<content.metailDtos.length;i++){
                            metailDtosArr.push(content.metailDtos[i].value);
                        }
                        var spoilageTotalMapsArr=[];//耗损物料总重
                        for(var i=0;i<content.spoilageTotalMaps.length;i++){
                            spoilageTotalMapsArr.push(content.spoilageTotalMaps[i].value);
                        }
                        var probabilityArr=[];
                        for(var i=0;i<content.spoilageTotalMaps.length;i++){
                            //((spoilageTotalMaps/metailDtos)*100).toFixed(4),
                            var spoilageTotalMapsVal=parseInt(content.spoilageTotalMaps[i].value);
                            var metailDtosVal=parseInt(content.metailDtos[i].value);
                            if(spoilageTotalMapsVal!=0&&metailDtosVal!=0){
                                probabilityArr.push(((spoilageTotalMapsVal/metailDtosVal)*100).toFixed(4));
                            }else{
                                probabilityArr.push(0);
                            }

                        }
                        option3.series=[
                            {
                                name:'领取物料总重',
                                type:'bar',
                                label: {
                                    normal: {
                                        show: true,
                                        fontSize:fontSize,
                                        position: 'top',
                                        formatter: "{c}"
                                    }
                                },
                                data:metailDtosArr
                            },
                            {
                                name:'耗损物料总重',
                                type:'bar',
                                label: {
                                    normal: {
                                        show: true,
                                        fontSize:fontSize,
                                        position: 'top',
                                        formatter: "{c}"
                                    }
                                },
                                data:spoilageTotalMapsArr
                            },
                            {
                                name:'物料损耗率',
                                type:'line',
                                yAxisIndex: 1,
                                symbolSize:fontSize,
                                smooth: true,
                                label: {
                                    normal: {
                                        show: true,
                                        fontSize:fontSize,
                                        formatter: "{c}%"
                                    }
                                },
                                data:probabilityArr
                            }
                        ];
                        myChart.hideLoading();
                        if(dataType!='1'){$('.chartBox').animate({scrollLeft: 0}, 1);}
                        myChart.setOption(option3,true);
                    }
                }else{
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });
    }
    //人员生产效率--注塑  3
    function productivityOfPlastic() {
        var url='/mes/statis/productivityOfPlastic';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {
            "type":'',
            "equipmentId":'',
            "equipmentType":'',
            "parentRelationship":'',
            "orgGroup":'',
            "yeas":''
        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        console.log(Decrypt(parameter));
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            data:JSON.stringify(
                {"parameter":parameter}
            ),
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                console.log(data)
                if(data.code==100){
                    var content=Decrypt(data.content);
                    content=JSON.parse(content);
                    console.log(content)

                    option3.legend.data=['实际产出数','理论产出数','生产效率'];
                    option3.yAxis[0].name='零件产出数（个）';
                    option3.yAxis[1].name='生产效率';

                    var actualMonthArr=[];//实际产出数
                    for(var i=0;i<content.actualMonth.length;i++){
                        actualMonthArr.push(content.actualMonth[i].value);
                    }
                    var theoryMonthArr=[];//理论产出数
                    for(var i=0;i<content.theoryMonth.length;i++){
                        theoryMonthArr.push(content.theoryMonth[i].value);
                    }
                    var probabilityArr=[]; //生产效率
                    for(var i=0;i<content.actualMonth.length;i++){
                        //((actualMonth/theoryMonth)*100).toFixed(4),
                        var actualMonthVal=parseInt(content.actualMonth[i].value);
                        var theoryMonthVal=parseInt(content.theoryMonth[i].value);
                        if(actualMonthVal!=0&&theoryMonthVal!=0){
                            probabilityArr.push(((actualMonthVal/theoryMonthVal)*100).toFixed(4));
                        }else{
                            probabilityArr.push(0);
                        }
                    }
                    option3.series=[
                        {
                            name:'实际产出数',
                            type:'bar',
                            label: {
                                normal: {
                                    show: true,
                                    fontSize:fontSize,
                                    position: 'top',
                                    formatter: "{c}"
                                }
                            },
                            data:actualMonthArr
                        },
                        {
                            name:'理论产出数',
                            type:'bar',
                            label: {
                                normal: {
                                    show: true,
                                    fontSize:fontSize,
                                    position: 'top',
                                    formatter: "{c}"
                                }
                            },
                            data:theoryMonthArr
                        },
                        {
                            name:'生产效率',
                            type:'line',
                            yAxisIndex: 1,
                            symbolSize:fontSize,
                            smooth: true,
                            label: {
                                normal: {
                                    show: true,
                                    fontSize:fontSize,
                                    formatter: "{c}%"
                                }
                            },
                            data:probabilityArr
                        }
                    ];
                    myChart.hideLoading();
                    if(dataType!='1'){$('.chartBox').animate({scrollLeft: 0}, 1);}
                    myChart.setOption(option3,true);
                }else{
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });
    }
    //人员生产率---金属&模具  3
    function productivityOfMetalAndMould() {
        var url='/mes/statis/productivityOfMetalAndMould';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {
            "type":'',
            "equipmentId":'',
            "equipmentType":'',
            "parentRelationship":'',
            "orgGroup":'',
            "yeas":''
        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        console.log(Decrypt(parameter));
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            data:JSON.stringify(
                {"parameter":parameter}
            ),
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                console.log(data)
                if(data.code==100){
                    var content=Decrypt(data.content);
                    content=JSON.parse(content);
                    console.log(content)
                    option3.legend.data=['实际所用工时','理论所需工时','生产效率'];
                    option3.yAxis[0].name='工时（小时）';
                    option3.yAxis[1].name='生产效率';

                    var actualUseTimeMonthArr=[];//实际所用工时
                    for(var i=0;i<content.actualUseTimeMonth.length;i++){
                        actualUseTimeMonthArr.push(content.actualUseTimeMonth[i].value);
                    }
                    var arrangeMonthArr=[];//理论所需工时
                    for(var i=0;i<content.arrangeMonth.length;i++){
                        arrangeMonthArr.push(content.arrangeMonth[i].value);
                    }
                    var probabilityArr=[];//生产效率
                    for(var i=0;i<content.actualUseTimeMonth.length;i++){
                        //((spoilageTotalMaps/metailDtos)*100).toFixed(4),
                        var actualUseTimeMonthVal=parseInt(content.actualUseTimeMonth[i].value);
                        var arrangeMonthVal=parseInt(content.arrangeMonth[i].value);
                        probabilityArr.push(((actualUseTimeMonthVal/arrangeMonthVal)*100).toFixed(4));
                    }
                    option3.series=[
                        {
                            name:'实际所用工时',
                            type:'bar',
                            label: {
                                normal: {
                                    show: true,
                                    fontSize:fontSize,
                                    position: 'top',
                                    formatter: "{c}"
                                }
                            },
                            data:actualUseTimeMonthArr
                        },
                        {
                            name:'理论所需工时',
                            type:'bar',
                            label: {
                                normal: {
                                    show: true,
                                    fontSize:fontSize,
                                    position: 'top',
                                    formatter: "{c}"
                                }
                            },
                            data:arrangeMonthArr
                        },
                        {
                            name:'生产效率',
                            type:'line',
                            yAxisIndex: 1,
                            symbolSize:fontSize,
                            smooth: true,
                            label: {
                                normal: {
                                    show: true,
                                    fontSize:fontSize,
                                    formatter: "{c}%"
                                }
                            },
                            data:probabilityArr
                        }
                    ];
                    myChart.hideLoading();
                    if(dataType!='1'){$('.chartBox').animate({scrollLeft: 0}, 1);}
                    myChart.setOption(option3,true);

                }else{
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });
    }

    //人员工时占比   1
    function queryPersonalOccupationTime() {
        var url='/mes/statis/queryPersonalOccupationTime';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {

        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        console.log(Decrypt(parameter));
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            data:JSON.stringify(
                {"parameter":parameter}
            ),
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                console.log(data)
                if(data.code==100){
                    $('.spinner').hide();
                    $('.main').show();
                    var content=Decrypt(data.content);
                    content=JSON.parse(content);
                    console.log(content)
                    option1.legend.data=content.legendData;
                    option1.series[0].data=content.seriesData;
                    myChart.hideLoading();
                    $('.chartBox').animate({scrollLeft: ($('.chart').width() / 3)}, 1);
                    myChart.setOption(option1,true);
                }else{
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                $('.spinner').hide();
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });
    }
    //生产单进度  4
    function queryProductionSchedule() {
        var url='/mes/statis/queryProductionSchedule';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {

        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        console.log(Decrypt(parameter));
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            data:JSON.stringify(
                {"parameter":parameter}
            ),
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                console.log(data)
                if(data.code==100){
                    var content=Decrypt(data.content);
                    content=JSON.parse(content);
                    console.log(content)

                    Xtype=content.xUnit;
                    splitNumberLen=content.monthOfDay;
                    option4.yAxis.data=content.yData;
                    option4.series[0].data=content.planData;
                    option4.series[1].data=content.actualPlanData;
                    option4.series[2].data=content.actualData;

                    myChart.hideLoading();
                    if(dataType!='1'){$('.chartBox').animate({scrollLeft: 0}, 1);}
                    myChart.setOption(option4,true);
                }else{
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });
    }
    //设备有效稼动率 3
    function queryEffectLeisureRate() {
        var url='/mes/statis/queryEffectLeisureRate';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {

        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        console.log(Decrypt(parameter));
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            data:JSON.stringify(
                {"parameter":parameter}
            ),
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                console.log(data)
                if(data.code==100){
                    var content=Decrypt(data.content);
                    content=JSON.parse(content);
                    console.log(content)

                    option3.legend.data=['平均有效稼动时间','平均理论稼动时间','有效稼动率'];
                    option3.yAxis[0].name='时间（小时）';
                    option3.yAxis[1].name='有效稼动率';

                    option3.series=[
                        {
                            name:'平均有效稼动时间',
                            type:'bar',
                            label: {
                                normal: {
                                    show: true,
                                    fontSize:fontSize,
                                    position: 'top',
                                    formatter: "{c}"
                                }
                            },
                            data:content.actualTimeArray
                        },
                        {
                            name:'平均理论稼动时间',
                            type:'bar',
                            label: {
                                normal: {
                                    show: true,
                                    fontSize:fontSize,
                                    position: 'top',
                                    formatter: "{c}"
                                }
                            },
                            data:content.theoryTimeArray
                        },
                        {
                            name:'有效稼动率',
                            type:'line',
                            yAxisIndex: 1,
                            symbolSize:fontSize,
                            smooth: true,
                            label: {
                                normal: {
                                    show: true,
                                    fontSize:fontSize,
                                    formatter: "{c}%"
                                }
                            },
                            data:content.rateArray
                        }
                    ];
                    myChart.hideLoading();
                    if(dataType!='1'){$('.chartBox').animate({scrollLeft: 0}, 1);}
                    myChart.setOption(option3,true);
                }else{
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });
    }
    //综合设备效率  2
    function queryCompositeEquipmentRate() {
        var url='/mes/statis/queryCompositeEquipmentRate';
        var mdObj=md5Fun(appUserId,url,appToken);
        var parameterObj= {

        };
        var parameter=Encrypt(JSON.stringify(parameterObj));
        console.log(Decrypt(parameter));
        $.ajax({
            type: "POST",
            timeout : 5000,
            url: webUrlCon+url,
            data:JSON.stringify(
                {"parameter":parameter}
            ),
            beforeSend: function(request) {
                request.setRequestHeader("Content-Type", "application/json");
                request.setRequestHeader("sequence", mdObj.sequence);
                request.setRequestHeader("nonceStr", mdObj.nonceStr);
                request.setRequestHeader("userId", appUserId);
                request.setRequestHeader("token",appToken);
                //xmlhttp.setRequestHeader("infName", url);
                //xmlhttp.setRequestHeader("osVersion", '');
                request.setRequestHeader("versionType", "1");
                request.setRequestHeader("osPlatform", mdObj.osPlatform);
                request.setRequestHeader("appVersion", mdObj.appVersion);
                request.setRequestHeader("sign", mdObj.sign);
            },
            success: function (data) {
                console.log(data)
                if(data.code==100){
                    var content=Decrypt(data.content);
                    content=JSON.parse(content);
                    console.log(content)

                    option2.series[0].data=content.statisticsRateArray;
                    option2.series[1].data=content.productivityRateArray;
                    option2.series[2].data=content.sufficeRateArray;
                    option2.series[3].data=content.compositeRateArray;
                    myChart.hideLoading();
                    if(dataType!='1'){$('.chartBox').animate({scrollLeft: 0}, 1);}
                    myChart.setOption(option2,true);
                }else{
                    layer.open({
                        content: data.code+' '+data.message
                        ,btn: '确定'
                    });
                }
            },
            error: function(e) {
                layer.open({
                    content: '无法请求服务器，请稍后再试！'
                    ,btn: '确定'
                });
            }
        });
    }

    /* 请求方法 END*/
    var dataType='';//图表类型
    $('.topNavTypeUl li').click(function () {
        //居中
        $('.chartBox').animate({scrollLeft: ($('.chart').width() / 3)}, 1);
        dataType=$(this).attr('data-type');
        var dataUrl=$(this).attr('data-url');
        myChart.showLoading();
        if(dataType=='1'){   //扇形图
            if(dataUrl=='queryMaterialDate'){ //物料统计 所占物料总重比例
                queryMaterialDate($(this).attr('data-url-type'));
            }else if(dataUrl=='queryPersonalOccupationTime'){ //人员工时占比
                queryPersonalOccupationTime();
            }
        }else if(dataType=='2'){   //拆线图
            if(dataUrl=='queryCompositeEquipmentRate'){
                queryCompositeEquipmentRate(); //综合设备效率
            }
        }else if(dataType=='3'){  //拆线树状图表
            if(dataUrl=='queryMaterialDate'){
                queryMaterialDate($(this).attr('data-url-type')); //物料统计 所占物料总重比例
            }else if(dataUrl=='productivityOfPlastic'){  //人员生产效率--注塑
                productivityOfPlastic();
            }else if(dataUrl=='productivityOfMetalAndMould'){ //统计人员生产率---金属&模具
                productivityOfMetalAndMould();
            }else if(dataUrl=='queryEffectLeisureRate'){ //设备有效稼动率
                queryEffectLeisureRate();
            }

        }else if(dataType=='4'){  //进度图
            if(dataUrl=='queryProductionSchedule'){
                queryProductionSchedule(); //生产单进度
            }
        }

    })




})